



#delimit ;
global labels1 
	"
	r_decline_nloss "Pessimist"  
	r_loss "Memory loss" 
	r_loss_a "Aware" 
	r_loss_u "Unaware" 
	lh_atotb "Wealth$_{t-1}$"
	h_atotbc "$\Delta$ Wealth$_{t}$"
	ltot_r "Recall$_{t-1}$"
	age "Age"
	HS "High school"
	college "College degree"
	female "Female"
	black "Black"
	other "Other races"
	lwork "Working$_{t-1}$"
	lalone "Single $_{t-1}$"
	h_child "Children"
	p_death_new "Partner death$_t$"
	lqrec "Memory score$_t-1$ (quartiles)"
	lgood "Very good health$_{t-1}$"
	ladl " ADL limitations$_{t-1}$ "

	"
	;	
global labels2
	"	
	"
	;
#delimit cr


set more off


global X "c.age##c.age  i.t  i.mstat  hs college i.lbrf ragender i.raracem i.cendiv ad_impw_atotb"
global XI "c.age##c.age  i.t  i.mstat  hs college i.lbrf ragender i.raracem i.cendiv"

global treat1 " r_loss_a r_loss_u   r_decline_nloss"
*for testing puroposes
global treat2 " r_loss  r_loss_u   r_decline_nloss"

  qui {

cap log close
log using Tables_Appendix, t replace
  

********************************************************************
******Table B.1: Severe memory loss events and switching state *****
********************************************************************


 use  wsample1, replace
 	qui  reg h_atotbc  r_loss  $X if lfinr==1  [pw=wtresp] 

  keep if  e(sample)==1
		  
bysort hhidpn (t): gen n=_n
bysort hhidpn (t): gen N=_N

 bysort hhidpn (t): gen E=(r_loss==1)
 bysort hhidpn (t): gen EU=(r_loss_u==1)
 bysort hhidpn (t): gen EA=(r_loss_a==1)

 
 gen EN=E if n==1
 bysort hhidpn (t):  replace EN=E+EN[_n-1] if n>1 & r_loss!=.

 gen EN_u=EU if n==1
 bysort hhidpn (t):  replace EN_u=EU+EN_u[_n-1] if n>1

gen EN_a=EA if n==1
 bysort hhidpn (t):  replace EN_a=EA+EN_a[_n-1] if n>1  
 
 
 bysort hhidpn (t):  egen ET=total(E)
 bysort hhidpn (t):  egen ET_a=total(EA)
 bysort hhidpn (t):  egen ET_u=total(EU)

 
 bysort hhidpn (t): egen first_r_loss = ifirst(r_loss) ,v(1) 
 bysort hhidpn (t): egen first_r_loss_u = ifirst(r_loss_u) ,v(1) 
 bysort hhidpn (t): egen first_r_loss_a = ifirst(r_loss_a) ,v(1) 
 gen temp= (first_r_loss==1 &first_r_loss_u==1)
 
 bysort hhidpn (t): egen sample_u=total(temp)
 drop temp
 
 gen temp= (first_r_loss==1 &first_r_loss_a==1)
 bysort hhidpn (t): egen sample_a=total(temp)
 drop temp 
 
 gen ET_ex_u=ET==ET_u if ET>0
 gen ET_ex_a=ET==ET_a if ET>0
 
gen switch_u=sample_u==1 & ET_ex_u==0
replace switch_u=. if sample_u==0
gen switch_a=sample_a==1 & ET_ex_a==0
replace switch_a=. if sample_a==0
 
gen noloss=ET==0
bysort hhidpn (year): egen first_wave = min(year) 

preserve

gen ET2=ET
	collapse noloss ET* switch_* sample_u sample_a N if  lfinr==1, by(hhidpn)
	   noi di "************Table B1************"

noi  table ET, stat(count ET2) stat(total sample_u) stat(mean switch_u) stat(total sample_a) stat (mean switch_a)
 restore
 
 
 *******************************************************************
******Table B.2: Transition rates **********************************
********************************************************************
  
  use wsample1, clear
  gen state=0 if r_loss==0
replace state=1 if r_decline_nloss==1
replace state=2 if r_loss_a==1
replace state=3 if r_loss_u==1
label define state 0 "no loss" 1 "pessimist" 2 "aware" 3 "unaware"
label value state state
gen state_t1=F.state
gen state_t2=F2.state
label value state_t1 state
label value state_t2 state

qui  reg h_atotbc  r_loss  $X if lfinr==1  [pw=wtresp] 

   noi di "************Table B2************"
 noi table state    [aw=wtresp] if e(sample), stat(fvpercent state_t1)
   
 tabout state state_t1  using tr_matrix1.txt [aw=wtresp] if e(sample),   style (tex) replace cells(row)

 
 
 *******************************************************************
******Table B.3: Heterogeneity by age and employment****************
********************************************************************
  
    use wsample1, clear
 keep if lfinr==1
 
 forvalue n=0/1{
reg h_atotbc $treat1 lqrec lh_atotb  $X if lwork==`n'   [pw=wtresp] , r cluster (hhid)
	estadd ysumm,mean
		 sum h_atotb if e(sample)
		estadd r(mean)
		 egen id=group(hhidpn) if e(sample)
		 sum id
		estadd r(max)
		drop id
est store emp`n'

reg h_atotbc $treat2 lqrec lh_atotb  $X if  lwork==`n'   [pw=wtresp] , r cluster (hhid)
est store emp`n'_t

}

 tempvar old
 gen `old'=age>10

forvalue n=0/1 {
reg h_atotbc $treat1 lqrec lh_atotb  $X if `old'==`n' [pw=wtresp] , r cluster (hhid)
	estadd ysumm,mean
			 sum h_atotb if e(sample)
		estadd r(mean)
 egen id=group(hhidpn) if e(sample)
		 sum id
		estadd r(max)
		drop id
est store age`n'


reg h_atotbc  $treat2 lqrec lh_atotb  $X if  `old'==`n' [pw=wtresp] , r cluster (hhid)

est store age`n'_t

}

  
  
   noi di "************Table B3************"


 noi estout	 	 emp1 emp0 age0 age1, 		///
	style(tex) stard cells(b(star fmt(%9.3f)) se(par)) stats(N max mean ymean ,labels("Obs." "N" "Mean W" "Mean $\Delta$ W") fmt(%9.5g))  ///
	starlevels(* 0.100 ** 0.05 *** 0.01)  keep(  r_loss_a r_loss_u  ) varl( $labels ) nolz	


		

 noi estout	 	 emp1_t emp0_t age0_t age1_t, 		///
	style(tex) stard cells(b(star fmt(%9.3f)) se(par)) stats(N )   starlevels(* 0.100 ** 0.05 *** 0.01)  ///		 
				indicate(  , labels(YES NO)) keep(   r_loss_u  ) varl( $labels ) nolz	


				
*******************************************************
*********Table B.4: heterogeneity by gender************
*******************************************************


forvalue n=0/1 {

   reg h_atotbc  $treat1 lqrec lh_atotb  $X  if  female==`n' [pw=wtresp] , r cluster (hhid)
  	 sum h_atotb if e(sample)
		estadd r(mean)
	estadd ysumm,mean
 egen id=group(hhidpn) if e(sample)
		 sum id
		estadd r(max)
		drop id
est store f`n'


   reg h_atotbc  $treat1 lqrec lh_atotb  $X  if  female==`n' & q4bw>3 [pw=wtresp] , r cluster (hhid)
  estadd ysumm,mean
			 sum h_atotb if e(sample)
		estadd r(mean)
 egen id=group(hhidpn) if e(sample)
		 sum id
		estadd r(max)
		drop id
est store f`n'_r


   reg h_atotbc  $treat1 lqrec lh_atotb  $X  if  lfinr==1 & female==`n' & q4bw<2 [pw=wtresp] , r cluster (hhid)
 estadd ysumm,mean
			 sum h_atotb if e(sample)
		estadd r(mean)
 egen id=group(hhidpn) if e(sample)
		 sum id
		estadd r(max)
		drop id
est store f`n'_p


   *test
   reg h_atotbc  r_decline_nloss r_loss r_loss_u lqrec lh_atotb  $X  if   female==`n' [pw=wtresp] , r cluster (hhid)
  	 sum h_atotb if e(sample)
		estadd r(mean)
est store f`n'_t



   reg h_atotbc  r_decline_nloss r_loss r_loss_u lqrec lh_atotb  $X  if  female==`n' & q4bw>3 [pw=wtresp] , r cluster (hhid)
  	 sum h_atotb if e(sample)
		estadd r(mean)
est store f`n'_r_t


   reg h_atotbc  r_decline_nloss r_loss r_loss_u lqrec lh_atotb  $X  if  lfinr==1 & female==`n' & q4bw<2 [pw=wtresp] , r cluster (hhid)
  	 sum h_atotb if e(sample)
		estadd r(mean)
est store f`n'_p_t
  
}

   noi di "************Table B4************"

	noi estout	 f0 f1  f0_p f1_p  f0_r f1_r , 		///
		style(tex) stard cells(b(star fmt(%9.3f)) se(par)) stats(N max mean ymean ,labels("Obs." "N" "Mean W" "Mean $\Delta$ W") fmt(%9.5g))  ///
	starlevels(* 0.100 ** 0.05 *** 0.01)  keep(  r_loss_a r_loss_u  ) varl( $labels ) nolz	


	noi estout	 f0_t f1_t  f0_p_t f1_p_t f0_r_t  f1_r_t , 		///
		style(tex) stard cells(b(star fmt(%9.3f)) se(par))    starlevels(* 0.100 ** 0.05 *** 0.01)  ///		 
				keep( r_loss_u    ) varl( $labels ) nolz		
	

*****************************************************************
*******Table B.5: Memory loss, stress, and  financial control****
*****************************************************************

	 	use wsample1, clear
	keep if lfinr==1


 
   		forvalue n=1/2 {
			if `n'==1 {
	local treat $treat1
			}
			else {
				local treat $treat2
			}
			
 foreach y  of varlist cesd stress_e  lifesat_c contr_fin optimism_c diffm {
reg `y'  `treat'  lqrec lh_atotb $X if  lfinr==1   [pw=wtresp] , r cluster (hhid)
estadd ysumm,mean
 egen id=group(hhidpn) if e(sample)
	 sum id
	estadd r(max)
	drop id	
est store `y'_`n'
	}
 }
   noi di "************Table B5************"

	      noi estout	 cesd_1 optimism_c_1 lifesat_c_1 contr_fin_1  stress_e_1 diffm_1, 		///
		style(tex) stard cells(b(star fmt(%9.3f)) se(par)) stats(N max mean ymean ,labels("Obs." "N" "Mean W" "Mean $\Delta$ W") fmt(%9.5g))   ///
	starlevels(* 0.100 ** 0.05 *** 0.01)  keep(  r_loss_a r_loss_u  ) varl( $labels ) nolz	

 
 

	      noi estout	 cesd_2 optimism_c_2 lifesat_c_2 contr_fin_2  stress_e_2 diffm_2, 		///
	style(tex) stard cells(b(star fmt(%9.3f)) se(par)) stats(N mean ymean max)   starlevels(* 0.100 ** 0.05 *** 0.01)  ///		 
				 	keep( r_loss_u    ) varl( $labels ) nolz	

***********************************************************************************************				
***********Table B.6 Excluding those with Health shock and hospitalizations********************
***********************************************************************************************				

  use wsample1,clear 
  keep if lfinr==1



   reg h_atotbc  $treat1 lqrec lh_atotb  $X   [pw=wtresp] , r cluster (hhid)
  	 sum h_atotb if e(sample)
		estadd r(mean)
		estadd ysumm,mean
 egen id=group(hhidpn) if e(sample)
	 sum id
	estadd r(max)
	drop id	
est store H0

   reg h_atotbc  $treat1  lqrec lh_atotb  $X if  h_shock==0 [pw=wtresp] , r cluster (hhid)	
  	 sum h_atotb if e(sample)
		estadd r(mean)
		estadd ysumm,mean
 egen id=group(hhidpn) if e(sample)
	 sum id
	estadd r(max)
	drop id	
est store H1

  reg h_atotbc  $treat1  lqrec lh_atotb  $X if  hosp==0 & h_shock==0 [pw=wtresp] , r cluster (hhid)	
  	 sum h_atotb if e(sample)
		estadd r(mean)
		estadd ysumm,mean
 egen id=group(hhidpn) if e(sample)
	 sum id
	estadd r(max)
	drop id	
est store H2




reg h_atotbc  $treat2 lqrec lh_atotb  $X  [pw=wtresp] , r cluster (hhid)	
est store H0_t

   reg h_atotbc  $treat2 lqrec lh_atotb  $X if  h_shock==0 [pw=wtresp] , r cluster (hhid)	
est store H1_t

  reg h_atotbc  $treat2 lqrec lh_atotb  $X if  hosp==0 & h_shock==0 [pw=wtresp] , r cluster (hhid)	
est store H2_t
	
		
***********************excluding potentially impaired**********************

	

	
	reg h_atotbc   $treat1   $X  lqrec  lh_atotb if  mstot>8 [pw=wtresp] , r cl(hhid) 
				 sum h_atotb if e(sample)
		estadd r(mean)
		estadd ysumm,mean
 egen id=group(hhidpn) if e(sample)
	 sum id
	estadd r(max)
	drop id	
		est store B1
			
		
		reg h_atotbc   $treat1    $X  lqrec  lh_atotb  if  lqrec>1 [pw=wtresp] , r cl(hhid) 
			 sum h_atotb if e(sample)
		estadd r(mean)
		estadd ysumm,mean
 egen id=group(hhidpn) if e(sample)
	 sum id
	estadd r(max)
	drop id	
		est store B2
		
		
	reg h_atotbc   $treat2  $X  lqrec  lh_atotb  if  mstot>8 [pw=wtresp] , r cl(hhid) 
		est store B1_t
		
	reg h_atotbc   $treat2    $X  lqrec  lh_atotb  if  lqrec>1 [pw=wtresp] , r cl(hhid) 
		est store B2_t

 
   noi di "************Table B6************"

  
	noi estout	 	 H0 H1 H2 B1 B2, 		///
	style(tex) stard cells(b(star fmt(%9.3f)) se(par)) stats(N max mean ymean ,labels("Obs." "N" "Mean W" "Mean $\Delta$ W" ) fmt(%9.5g))  ///
	starlevels(* 0.100 ** 0.05 *** 0.01)  	 keep(r_loss_a r_loss_u r_decline_nloss) varl( $labels ) nolz	
   
	noi estout	 	 H0_t H1_t H2_t B1_t B2_t, 		///
	style(tex) stard cells(b(star fmt(%9.3f)) se(par))  ///
	starlevels(* 0.100 ** 0.05 *** 0.01)  	 keep( r_loss_u) varl( $labels ) nolz	

***********************************************************************************************				
************************Table B.7 Changes in Consumptions**************************************
***********************************************************************************************				


foreach y of varlist cams_ctots cams_cdurs cams_cndur    cams_chouss cams_ctranss  cams_cmort {

	reg `y'c  $treat1 lqrec lh_atotb $X  i.cams_ctotsf cams_cncat     [pw=cams_cwgtr] , r cluster (hhid)
		sum `y' if e(sample)
		estadd r(mean)
		estadd ysumm,mean
		egen id=group(hhidpn) if e(sample)
		sum id
		estadd r(max)
		drop id	
		est store `y'c
			

}


  
  
 
foreach y of varlist cams_ctotsc cams_cdursc cams_cndurc    cams_choussc cams_ctranssc  cams_cmortc {

	reg `y'  $treat2 lqrec lh_atotb $X i.cams_ctotsf cams_cncat      [pw=cams_cwgtr] , r cluster (hhid)
			est store  `y'_t
}

   noi di "************Table B7************"

  noi estout	 cams_ctotsc cams_cdursc cams_cndurc    cams_choussc cams_ctranssc   	  , 		///
	style(tex) stard cells(b(star fmt(%9.3f)) se(par)) stats(N mean ymean max,labels("Obs." "Mean" "Mean $\Delta$" "N") fmt(%9.5g))   starlevels(* 0.100 ** 0.05 *** 0.01)  ///		 
				keep( r_loss_a r_loss_u ) varl( $labels ) nolz	

  noi estout	 cams_ctotsc_t cams_cdursc_t cams_cndurc_t    cams_choussc_t cams_ctranssc_t   	  , 		///
	style(tex) stard cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.100 ** 0.05 *** 0.01)  ///		 
				keep( r_loss_u   ) varl( $labels ) nolz	
   
**********************************************************************************************
************************Table B.8 Transfers***************************************************
**********************************************************************************************			

	  
	  
	reg transferc r_loss  r_decline  lqrec lh_atotb $X  [pw=wtresp] , r cluster (hhid)
		 sum transfer if e(sample)
		estadd r(mean)
		estadd ysumm,mean
		 egen id=group(hhidpn) if e(sample)
		 sum id
		estadd r(max)
				drop id
  est store TRP_0
  *no differences in the amount conditional on transfer. Some difference unconditional
  reg chtr_amountc r_loss r_decline  lqrec lh_atotb $X      [pw=wtresp] , r cluster (hhid)
   	 sum chtr_amount if e(sample)
		estadd r(mean)
		estadd ysumm,mean
		 egen id=group(hhidpn) if e(sample)
		 sum id
		estadd r(max)
				drop id
	est store TRA_0
  *less likely to make a transfer to children
  reg transferc $treat1 lqrec lh_atotb $X     [pw=wtresp] , r cluster (hhid)
 	 sum transfer if e(sample)
		estadd r(mean)
		estadd ysumm,mean
		 egen id=group(hhidpn) if e(sample)
		 sum id
		estadd r(max)
				drop id
  est store TRP_1
  *no differences in the amount conditional on transfer. Some difference unconditional
  reg chtr_amountc  $treat1  lqrec lh_atotb $X     [pw=wtresp] , r cluster (hhid)
  sum chtr_amount if e(sample)
		estadd r(mean)
		estadd ysumm,mean
		 egen id=group(hhidpn) if e(sample)
		 sum id
		estadd r(max)
				drop id
  est store TRA_1
	
 

	
	reg transferc r_loss  r_decline  lqrec lh_atotb $X     [pw=wtresp] , r cluster (hhid)
  est store TRP_0_t
  *not differences in the amount conditional on transfer. Some difference unconditional
  reg chtr_amountc r_loss r_decline  lqrec lh_atotb $X      [pw=wtresp] , r cluster (hhid)
	est store TRA_0_t
  *less likely to make a transfer to children
  reg transferc  $treat2 lqrec lh_atotb $X     [pw=wtresp] , r cluster (hhid)
  est store TRP_1_t
  *not differences in the amount conditional on transfer. Some difference unconditional
  reg chtr_amountc  $treat2  lqrec lh_atotb $X      [pw=wtresp] , r cluster (hhid)
  est store TRA_1_t
	
   noi di "************Table B8************"

 noi estout	  TRP_0 TRP_1 TRA_0 TRA_1, 		///
	style(tex) stard cells(b(star fmt(%9.3f)) se(par)) stats(N max mean ymean ,labels("Obs." "N" "Mean W" "Mean $\Delta$ W") fmt(%9.5g))  ///
	starlevels(* 0.100 ** 0.05 *** 0.01)  keep(r_loss  r_loss_a r_loss_u  ) varl( $labels ) nolz	

  noi estout	  TRP_0_t TRP_1_t TRA_0_t TRA_1_t, 		///
	style(tex) stard cells(b(star fmt(%9.3f)) se(par))   starlevels(* 0.100 ** 0.05 *** 0.01)  ///		 
				indicate( $indicate1 , labels(YES NO)) ///
				keep(   r_loss_u ) varl( $labels ) nolz	

***********************************************************************************************
************************Table B.9 Difference between actual and predicted financial wealth*****
***********************************************************************************************				

	   noi disp "actual vs. predicted wealth"

   reg diff_totf  $treat1   $X lqrec lh_atotf  if  lh_atotf>0  [pw=wtresp] , r cluster (hhid)
sum diff_totf if e(sample) , detail
	estadd r(mean)
	estadd ysumm,mean
	 egen id=group(hhidpn) if e(sample)
		 sum id
		estadd r(max)
		drop id	
est store AD

reg diff_totf  $treat1 lqrec  $X  lqrec lh_atotf  if  lh_atotf>0 & q4bw>2  [pw=wtresp] , r cluster (hhid)
sum diff_totf if e(sample) , detail
	estadd r(mean)
	estadd ysumm,mean
	 egen id=group(hhidpn) if e(sample)
		 sum id
		estadd r(max)
		drop id
est store ADQ

   
reg diff_totf  $treat2 lqrec  $X lqrec lh_atotf  if  lh_atotf>0 & r_loss==1  [pw=wtresp] , r cluster (hhid)
sum diff_totf if e(sample) , detail
	estadd r(mean)
	estadd ysumm,mean
	 egen id=group(hhidpn) if e(sample)
		 sum id
		estadd r(max)
		drop id
est store LAD

reg diff_totf  $treat2 lqrec  $X lqrec lh_atotf  if  lh_atotf>0 & q4bw>2  & r_loss==1 [pw=wtresp] , r cluster (hhid)
sum diff_totf if e(sample) , detail
	estadd r(mean)
	estadd ysumm,mean
	 egen id=group(hhidpn) if e(sample)
		 sum id
		estadd r(max)
		drop id
est store LADQ


		
reg diff_totf r_decline_nloss r_loss r_loss_u lqrec  $X  lh_atotf ad_impw_atotb if  lh_atotf>0  [pw=wtresp] , r cluster (hhid)
est store AD_t

reg diff_totf r_decline_nloss r_loss r_loss_u lqrec  $X  lh_atotf ad_impw_atotb if  lh_atotf>0 & q4bw>2  [pw=wtresp] , r cluster (hhid)
est store ADQ_t


   noi di "************Table B9************"

 noi estout	 	 AD ADQ LAD  LADQ, 		///
style(tex) stard cells(b(star fmt(%9.3f)) se(par)) stats(N max mean ymean ,labels("Obs." "N" "Mean W" "Mean $\Delta$ W" ) fmt(%9.5g))  ///
	starlevels(* 0.100 ** 0.05 *** 0.01)  	 keep(r_loss_a r_loss_u) varl( $labels ) nolz	
	
		
 noi estout	 	 AD_t ADQ_t , 		///
	style(tex) stard cells(b(star fmt(%9.3f)) se(par))    starlevels(* 0.100 ** 0.05 *** 0.01)  ///		 
				keep(  r_loss_u   ) varl( $labels ) nolz	

	
**********************************************************************************************************************
************************Table B.10 Imputation of asset values and assessed misreporting of assets*********************
**********************************************************************************************************************			

*Test on imputation and misreporting
 tempvar imp_stck
gen `imp_stck'=0 if f_h_astck<3
replace `imp_stck'= 1 if f_h_astck>3 & f_h_astck<6

	

  forvalue n=1/2 {
			if `n'==1 {
	local treat $treat1
			}
			else {
				local treat $treat2
			}
	
	reg `imp_stck'  `treat' $XI  lqrec lh_atotb   if   lh_atotf>0 [pw=wtresp] , r cluster (hhid)
	 sum `imp_stck'
	estadd r(mean)
	estadd ysumm,mean
	  egen id=group(hhidpn) if e(sample)
		 sum id
		estadd r(max)
				drop id
	est store imp_st_`n'
			
	foreach y of varlist ad_impw_atotf wrong wrong_fa {
	
	reg `y'   `treat' $XI  lqrec lh_atotb    [pw=wtresp] , r cluster (hhid)
	 sum `y'  if e(sample)
	estadd r(mean)
	estadd ysumm,mean
	  egen id=group(hhidpn) if e(sample)
	  
		 sum id
		estadd r(max)
				drop id		
est store `y'_`n'

		}
   
  }

   noi di "************Table B10************"

 noi estout	 	ad_impw_atotf_1 imp_st_1 wrong_1 wrong_fa_1 , 		///
	style(tex) stard cells(b(star fmt(%9.3f)) se(par)) stats(N max mean ymean ,labels("Obs." "N" "Mean W" "Mean $\Delta$ W") fmt(%9.5g))  ///
	starlevels(* 0.100 ** 0.05 *** 0.01)  keep(  r_loss_a r_loss_u  ) varl( $labels ) nolz	

				
	noi estout	 	ad_impw_atotf_2 imp_st_2 wrong_2 wrong_fa_2 , 		///
	style(tex) stard cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.100 ** 0.05 *** 0.01)  ///		 
				keep(   r_loss_u  ) varl( $labels ) nolz	

***********************************************************************************************
************************Table B.11 Changes in the logarithm of total wealths*******************
***********************************************************************************************				

			
  global C "lqrec llnh_atotb"
   
   
   
   		forvalue n=1/2 {
			if `n'==1 {
	local treat $treat1
			}
			else {
				local treat $treat2
			}
	 reg lnh_atotbc `treat' $X $C      [pw=wtresp] , r cluster (hhid)
	est store B0_`n'
		 sum h_atotb if e(sample)
		estadd r(mean)
		estadd ysumm,mean
		 egen id=group(hhidpn) if e(sample)
		 sum id
		estadd r(max)
		drop id
				
	forvalue q=1/4 {
    reg lnh_atotbc  `treat' $X $C   if q4bw==`q'    [pw=wtresp] , r cluster (hhid)
	est store T`q'_`n'
	 		 sum h_atotb if e(sample)
		estadd r(mean)
		estadd ysumm,mean
		 egen id=group(hhidpn) if e(sample)
		 sum id
		estadd r(max)
				drop id
	}
	
		}

   noi di "************Table B11************"

  noi estout	 	 B0_1 T1_1  T2_1  T3_1  T4_1 , 		///
	style(tex) stard cells(b(star fmt(%9.3f)) se(par)) stats(N max mean ymean ,labels("Obs." "N" "Mean W" "Mean $\Delta$ W") fmt(%9.5g)) ///  
	starlevels(* 0.100 ** 0.05 *** 0.01)  keep(  r_loss_a r_loss_u  ) varl( $labels ) nolz	


  noi estout	 	 B0_2 T1_2  T2_2  T3_2  T4_2 , 		///
	style(tex) stard cells(b(star fmt(%9.3f)) se(par))   starlevels(* 0.100 ** 0.05 *** 0.01)  ///		 
				indicate(  , labels(YES NO)) ///
				keep(  r_loss_u) varl( $labels ) nolz	
				
				
************************************************************************************************
****Table B.12 Changes in total wealth and absolute or relative changes in the memory score:****
************************************************************************************************			

	
use wsample1, clear
keep if lfinr==1

gen sa_loss=1-stablemem

xtile qdrec=dtot_rec, nq(5)
xtile r_qdrec=rel_memc, nq(5)





  qui  reg h_atotbc  $treat1 lqrec lh_atotb  $X  if  lfinr==1 [pw=wtresp] , r cluster (hhid)

   * absolute term
   reg h_atotbc   c.dtot_rec##c.sa_loss lqrec lh_atotb  $X  if e(sample)==1 [pw=wtresp] , r cluster (hhid)
  	 sum h_atotb if e(sample)
	estadd r(mean)
	estadd ysumm,mean
 egen id=group(hhidpn) if e(sample)
	 sum id
	estadd r(max)
	drop id	
   est store A_l
   reg h_atotbc   i.qdrec##c.sa_loss lqrec lh_atotb  $X  if e(sample)==1 [pw=wtresp] , r cluster (hhid)
   est store A_q
    reg h_atotbc   c.rel_memc##c.sa_loss lqrec lh_atotb  $X  if e(sample)==1 [pw=wtresp] , r cluster (hhid)
	 est store R_l
   reg h_atotbc   i.r_qdrec##c.sa_loss lqrec lh_atotb  $X  if e(sample)==1 [pw=wtresp] , r cluster (hhid)
	est store R_q

	   noi di "************Table B12************"

   
   noi estout	 	 A_l A_q R_l R_q , 		///
	style(tex) stard cells(b(star fmt(%9.3f)) se(par)) ren (rel_memc dtot_rec c.rel_memc#c.sa_loss c.dtot_rec#c.sa_loss 2.r_qdrec 2.qdrec 3.r_qdrec 3.qdrec 4.r_qdrec 4.qdrec 5.r_qdrec 5.qdrec ///
	2.r_qdrec#c.sa_loss 2.qdrec#c.sa_loss 3.r_qdrec#c.sa_loss 3.qdrec#c.sa_loss 4.r_qdrec#c.sa_loss 4.qdrec#c.sa_loss 5.r_qdrec#c.sa_loss 5.qdrec#c.sa_loss) ///
	keep (dtot_rec sa_loss c.dtot_rec#c.sa_loss 2.qdrec 3.qdrec 4.qdrec 5.qdrec 2.qdrec#c.sa_loss 3.qdrec#c.sa_loss 4.qdrec#c.sa_loss 5.qdrec#c.sa_loss) ///
	stats(N max mean ymean,labels("Obs." "N" "Mean W" "Mean $\Delta$ W") fmt(%9.5g))  starlevels(* 0.100 ** 0.05 *** 0.01)  		 
 
 
 ***********************************************************************************************************************
 ****Table B.13: Baseline estimates and excluding respondents who are aware, unaware or pessimists at t-1***************
 ***********************************************************************************************************************				

 use wsample1, clear
keep if lfinr==1


*test on different subsamples
  local S1   lfinr==1
  *local S2 `S1' & (switch_a!=1& switch_u!=1)
  *local S3  `S2'  & q4bw>2
  local S2 `S1' & lloss_a==0
  local S3 `S1' &  lloss_u==0
  local S4 `S1' &  ldecline==0
  local S5 `S1' &  ldecline==0 &lloss_u==0 &lloss_a==0
  
  forvalue n=1/5 {
  reg h_atotbc  $treat1  lqrec lh_atotb  $X [pw=wtresp] if `S`n''  , r cluster (hhid)
  		 sum h_atotb if e(sample)
		estadd r(mean)
		estadd ysumm,mean
 egen id=group(hhidpn) if e(sample)
	 sum id
	estadd r(max)
	drop id	
  est store b`n'
   reg h_atotbc  $treat2   lqrec lh_atotb   $X [pw=wtresp] if `S`n''  , r cluster (hhid)
  est store b`n'_t
  }
  
   noi di "************Table B13************"

  noi estout	b1 b2 b3 b4 b5, 		///
	style(tex) stard cells(b(star fmt(%9.3f)) se(par)) stats(N max mean ymean ,labels("Obs." "N" "Mean W" "Mean $\Delta$ W") fmt(%9.5g))  ///
	starlevels(* 0.100 ** 0.05 *** 0.01)  keep(  r_loss_a r_loss_u  ) varl( $labels ) nolz	

  noi estout	b1_t b2_t b3_t b4_t b5_t, 		///
	style(tex) stard cells(b(star fmt(%9.3f)) se(par))  ///
	starlevels(* 0.100 ** 0.05 *** 0.01)  keep(  r_loss_u  ) varl( $labels ) nolz	
 

***********************************************************************************************************************
**************** Table B14: OLS including polygenic scores (PGSs): Changes in total wealth*****************************
***********************************************************************************************************************

use wsample1, clear
keep if lfinr==1
			
local output b f



		reg h_atotbc $treat1 lqrec  lh_atotb $X if E4_GCOG2_CHARGE18!=. [pw=wtresp] , r cluster (hhid)
		   est store  PS_B0
		  	 sum h_atotb if e(sample)
		estadd r(mean)
		estadd ysumm,mean
	 egen id=group(hhidpn) if e(sample)
	 sum id
	estadd r(max)
	drop id	
		   
			reg h_atotbc $treat1 lqrec lh_atotb  E4_GCOG2_CHARGE18    $X [pw=wtresp] , r cluster (hhid)
		   est store  PS_C1
		  	 sum h_atotb if e(sample)
		estadd r(mean)
		estadd ysumm,mean
	 egen id=group(hhidpn) if e(sample)
	 sum id
	estadd r(max)
	drop id	
		   
			reg h_atotbc $treat1 lqrec lh_atotb  E4_GCOG2_CHARGE18 E4_EDU3_SSGAC18   $X  [pw=wtresp] ,r 	cluster (hhid)
		   est store  PS_C2
		  	 sum h_atotb if e(sample)
		estadd r(mean)
		estadd ysumm,mean
	 egen id=group(hhidpn) if e(sample)
	 sum id
	estadd r(max)
	drop id	
		   
		 reg h_atotbc $treat1 lqrec lh_atotb  E4_GCOG2_CHARGE18 E4_EDU3_SSGAC18  E4_GWAD2NA_IGAP19 $X [pw=wtresp] , r cluster (hhid)
		   est store  PS_C3
		  	 sum h_atotb if e(sample)
		estadd r(mean)
		estadd ysumm,mean
	 egen id=group(hhidpn) if e(sample)
	 sum id
	estadd r(max)
	drop id	
		   
		  
		  reg h_atotbc $treat2 lqrec lh_atotb  $X if lfinr==1  & E4_GCOG2_CHARGE18!=. [pw=wtresp] , r cluster (hhid)
		   est store  PS_B0_t
		   
			reg h_atotbc $treat2 lqrec lh_atotb  E4_GCOG2_CHARGE18    $X if lfinr==1 [pw=wtresp] , r cluster (hhid)
		   est store  PS_C1_t
		   
			reg h_atotbc $treat2 lqrec lh_atotb  E4_GCOG2_CHARGE18 E4_EDU3_SSGAC18   $X  [pw=wtresp] , r cluster (hhid)
		   est store  PS_C2_t
		   
		 reg h_atotbc$treat2 lqrec lh_atotb  E4_GCOG2_CHARGE18 E4_EDU3_SSGAC18  E4_GWAD2NA_IGAP19 $X  [pw=wtresp] , r cluster (hhid)
		   est store  PS_C3_t

		   
		      noi di "************Table B14************"

		noi	  estout	 PS_B0 PS_C1 PS_C2 PS_C3 , 		///
		style(tex) stard cells(b(star fmt(%9.3f)) se(par)) stats(N max mean ymean ,labels("Obs." "N" "Mean" "Mean" ) fmt(%9.5g))  ///
			starlevels(* 0.100 ** 0.05 *** 0.01)  keep(r_loss_u r_loss_a)	  nolz	

	noi			 estout	 PS_B0_t PS_C1_t PS_C2_t PS_C3_t , 		///
		style(tex) stard cells(b(star fmt(%9.3f)) se(par))   ///
			starlevels(* 0.100 ** 0.05 *** 0.01)  keep(r_loss_u )	  nolz	

***********************************************************************************************************************
***************Table B.15: Baseline static model with time-invariant individual-speciific fixed effects****************
***********************************************************************************************************************


  use wsample1, clear
  keep if lfinr==1
  

 reghdfe h_atotbc  $treat1 lqrec  $X  [pw=wtresp]  ,absorb (hhidpn t) cl(hhid) 
	est store BFE
		 sum h_atotb if e(sample)
		estadd r(mean)
		estadd ysumm,mean
 egen id=group(hhidpn) if e(sample)
	 sum id
	estadd r(max)
	drop id	
	
	
 reg h_atotbc  $treat1 lqrec lh_atotb  $X if e(sample)==1 [pw=wtresp] , r cluster (hhid)
	est store B0
		 sum h_atotb if e(sample)
		estadd r(mean)
		estadd ysumm,mean
 egen id=group(hhidpn) if e(sample)
	 sum id
	estadd r(max)
	drop id	
  

 reghdfe h_atotbc  $treat1 lqrec  $X  if q4bw>2  [pw=wtresp]  ,absorb (hhidpn t) cl(hhid) 
	est store RFE
		 sum h_atotb if e(sample)
		estadd r(mean)
		estadd ysumm,mean
 egen id=group(hhidpn) if e(sample)
	 sum id
	estadd r(max)
	drop id	
	
	
reg h_atotbc  $treat1 lqrec lh_atotb  $X if q4bw>2  & e(sample)==1 [pw=wtresp] , r cluster (hhid)
	est store R0
		 sum h_atotb if e(sample)
		estadd r(mean)
		estadd ysumm,mean
 egen id=group(hhidpn) if e(sample)
	 sum id
	estadd r(max)
	drop id	
  

 reghdfe h_atotbc  $treat2 lqrec  $X  [pw=wtresp]  ,absorb (hhidpn) cl(hhid) 
	est store BFE_t
	
reg h_atotbc  $treat2 lqrec lh_atotb  $X if e(sample)==1 [pw=wtresp] , r cluster (hhid)
	est store B0_t

		
  
 reghdfe h_atotbc $treat2 lqrec  $X  if q4bw>2 [pw=wtresp]  ,absorb (hhidpn) cl(hhid) 
	est store RFE_t
	
	
	reg h_atotbc  $treat2 lqrec lh_atotb  $X if q4bw>2 & e(sample)==1 [pw=wtresp] , r cluster (hhid)
	est store R0_t
	
	
			      noi di "************Table B15************"
  
 	noi		  estout	 B0 BFE R0 RFE , 		///
		style(tex) stard cells(b(star fmt(%9.3f)) se(par)) stats(N max mean ymean ,labels("Obs." "N" "Mean" "Mean" ) fmt(%9.5g))  ///
			starlevels(* 0.100 ** 0.05 *** 0.01)  keep(r_loss_u r_loss_a)	  nolz	

	noi			 estout	 B0_t BFE_t R0_t RFE_t , 		///
		style(tex) stard cells(b(star fmt(%9.3f)) se(par))   ///
			starlevels(* 0.100 ** 0.05 *** 0.01)  keep(r_loss_u )	  nolz	

***********************************************************************************************************************
***************Table B.16: DiD model with time-invariant individual-speciific fixed effects**************************
***********************************************************************************************************************

use wsample2,clear 


local letter b f
		foreach y of local  letter {
	
  reghdfe h_atot`y'c    post   post_u    $X    [pw=wtresp]  ,absorb (hhidpn t) cl(hhid) 
  	 sum h_atot`y' if e(sample)
		estadd r(mean)
		estadd ysumm,mean
		 egen id=group(hhidpn) if e(sample)
		 sum id
		estadd r(max)
		drop id
 est store PFE_`y'
 

  reghdfe h_atot`y'c    post  post_u     $X   if   (sample_a==1|sample_u==1)   [pw=wtresp] ,absorb (hhidpn t) cl(hhid) 
 	 sum h_atot`y' if e(sample)
		estadd r(mean)
		estadd ysumm,mean
		 egen id=group(hhidpn) if e(sample)
		 sum id
		estadd r(max)
		drop id
  est store PFE_R_`y'
		}

		
		   noi di "************Table B16************"

		
   		noi estout	   PFE_b  PFE_R_b  PFE_f  PFE_R_f , 		///
	style(tex) stard cells(b(star fmt(%9.3f)) se(par)) stats(N max mean ymean ,labels("Obs." "N" "Mean W" "Mean \Delta W"))  ///
	starlevels(* 0.100 ** 0.05 *** 0.01) keep(  post_u  post   ) nolz	

		
*****************************************************************************************************************
**************** Table B17: Preventive health care (outcomes in levels)******************************************
*****************************************************************************************************************

use wsample1, clear



foreach y of varlist prost mammog flusht cholst{

 qui  reg   `y' $treat1 lqrec lh_atotb $X   [pw=wtresp] , r cluster (hhid)
   est store `y'
   
  qui  reg   `y' $treat2 lqrec lh_atotb  $X  [pw=wtresp] , r cluster (hhid)
   est store `y'_t
 
   }
   
   
      noi di "************Table B17************"

   noi estout	prost mammog flusht cholst , 		///
	style(tex) stard cells(b(star fmt(%9.3f)) se(par)) stats(N max mean ymean ,labels("Obs." "N" "Mean W" "Mean $\Delta$ W" ) fmt(%9.5g))  ///
	starlevels(* 0.100 ** 0.05 *** 0.01)  	 keep(  r_loss_a r_loss_u) varl( $labels ) nolz	
   
	 noi estout	prost_t mammog_t flusht_t cholst_t, 		///
	style(tex) stard cells(b(star fmt(%9.3f)) se(par))   ///
	starlevels(* 0.100 ** 0.05 *** 0.01)  	 keep(  r_loss_u) varl( $labels ) nolz	

*************************************************************************************
**************** Table B18: Health Behavior******************************************
*************************************************************************************


   
   	 foreach y of varlist  drinkn  smoken dentst {

  qui  reg   `y'c $treat1 lqrec lh_atotb $X  [pw=wtresp] , r cluster (hhid)
   est store `y'c
   
     qui  reg   `y'c  $treat2 lqrec lh_atotb  $X  [pw=wtresp] , r cluster (hhid)
   est store `y'c_t
 
   }
 
 

    noi di "************Table B18************"

 
 	  noi estout  drinknc smokenc dentstc, 		///
	style(tex) stard cells(b(star fmt(%9.3f)) se(par)) stats(N max mean ymean ,labels("Obs." "N" "Mean W" "Mean $\Delta$ W" ) fmt(%9.5g))  ///
	starlevels(* 0.100 ** 0.05 *** 0.01)  	 keep(  r_loss_a r_loss_u) varl( $labels ) nolz	
   
	 noi estout	  drinknc_t smokenc_t dentstc_t, 		///
	style(tex) stard cells(b(star fmt(%9.3f)) se(par))   ///
	starlevels(* 0.100 ** 0.05 *** 0.01)  	 keep(  r_loss_u) varl( $labels ) nolz	
	
 
 
	
   
 	 foreach y of varlist henum lifein hiltc h_ins {

  qui  reg   `y'c $treat1 lqrec lh_atotb  $X   if lfinr==1 [pw=wtresp] , r cluster (hhid)
   est store `y'c
   
     qui  reg   `y'c $treat2 lqrec lh_atotb  $X  if lfinr==1  [pw=wtresp] , r cluster (hhid)
   est store `y'c_t
 
   }
   
*************************************************************************************
**************** Table B19: Health Behavior******************************************
*************************************************************************************


	
	
   noi di "************Table B19************"

 
  noi estout  h_insc  lifeinc hiltcc , ///
	 style(tex) stard cells(b(star fmt(%9.3f)) se(par)) stats(N max mean ymean ,labels("Obs." "N" "Mean W" "Mean $\Delta$ W" ) fmt(%9.5g))  ///
	starlevels(* 0.100 ** 0.05 *** 0.01)  	 keep(  r_loss_a r_loss_u) varl( $labels ) nolz		
	
   noi estout  h_insc_t  lifeinc_t hiltcc_t , ///
	 style(tex) stard cells(b(star fmt(%9.3f)) se(par))   ///
	starlevels(* 0.100 ** 0.05 *** 0.01)  	 keep(   r_loss_u) varl( $labels ) nolz		
	
	cap log close

}
